package com.qn.visitor.analyze.filter.strategy.guava;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;
import com.qn.visitor.analyze.filter.strategy.IAnalyzeFilter;

import static com.google.common.base.Charsets.UTF_8;
/**
 * qingniu-cloud user source analysis
 *
 * @Author: TXG
 * @Date: 2024/6/11
 * @Version V0.0.2
 */

public class UserAgentGuavaFilter implements IAnalyzeFilter {
    public static BloomFilter<String> filter = BloomFilter.create(
            Funnels.stringFunnel(UTF_8),
            1000 * 10000,
            0.0001);
    private static class UserAgentFilterInstance {
        private static final UserAgentGuavaFilter INSTANCE = new UserAgentGuavaFilter();
    }
    public static UserAgentGuavaFilter getInstance() {

        return UserAgentGuavaFilter.UserAgentFilterInstance.INSTANCE;
    }
    @Override
    public boolean filter(String hash) {
        return filter.mightContain(hash);
    }
    @Override
    public void add(String hash) {
        filter.put(hash);
    }

}